﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Myotragus.Data.Domain;
using Myotragus.Data.Util;

namespace Myotragus.Data.Metadata
{
	public class EntityDescriptor<TEntity> : IEntityDescriptor<TEntity>
		where TEntity : IEntity
	{
		protected static readonly Type TypeOfTEntity = typeof(TEntity);
		protected IDictionary<string, PropertyInfo> DicEntityProperties;

		public EntityDescriptor()
		{
			DicEntityProperties = CreatePropertiesDic(TypeOfTEntity);
		}

		public IDictionary<string, PropertyInfo> EntityProperties
		{
			get { return DicEntityProperties; }
		}

		protected static IDictionary<string, PropertyInfo> CreatePropertiesDic(Type type)
		{
			return ReflectionHelper.GetProperties(type).ToDictionary(p => p.Name, p => p);
		}
	}
}